<?php
/* 
 * Copyright (c) 2018-{{Y}}   All rights reserved.
 *
 * 创建时间：{{$YmdHi}}
 *
 * 项目：{{$classdir}}/levcc  -  $  - userModelHelper.php
 *
 * 作者：{{AUTO GENERATE}}
 */

//此文件使用程序自动生成，下次生成时【不会】覆盖。
//在这里可以补充、完善你的程序逻辑

namespace modules\levcc\table\pre_admin_user;

use Lev;

!defined('INLEV') && exit('Access Denied LEV');

class BaseUserModelMiddle extends BaseUserModel
{

    public static function saveForm($formPre = 'datax', $route = '', $form = null, $upData = null, $upDataForce = null, $opInfo = null)
    {
        !$formPre && $formPre = 'datax';

        $upData === null &&
        $upData = Lev::stripTags(Lev::POSTv($formPre));

        $opid = intval(Lev::GPv('opid'));

        $opInfo === null &&
        $opInfo = $opid >0 ? static::findOne(['id'=>$opid]) : [];

        return parent::saveForm($formPre, $route, $form, $upData, $upDataForce, $opInfo); // TODO: Change the autogenerated stub
    }

    public static function saveFormCall($upData, $opInfo = [], $upDataForce = null, $route = '', $form = null) {
        return static::saveForm('', $route, $form, $upData, $upDataForce, $opInfo);
    }

    /**
     * 额外的表单字段，不会存入数据库
     * @return array
     */
    public static function extInputs()
    {
        return parent::extInputs(); // TODO: Change the autogenerated stub
    }

    public static function headerHtm()
    {
        return parent::headerHtm(); // TODO: Change the autogenerated stub
        //return '<tips class="gray inblk scale8">自定义headerHtm：文件位置：'.__DIR__ . '/userModelHelper.php'.'</tips>';
    }

    public static function footerHtm()
    {
        return parent::footerHtm(); // TODO: Change the autogenerated stub
        //return '<tips class="gray inblk scale8">自定义footerHtm</tips>';
    }

    public static function footerFormInnerHtm()
    {
        return parent::footerFormInnerHtm(); // TODO: Change the autogenerated stub
        //return '<tips class="gray inblk scale8">自定义footerFormInnerHtm</tips>';
    }

    public static function staticInfo($opid, $opInfo = null) {
        static $infos;
        if ($opInfo !== null) {//更新缓存
            $opid = $opInfo['id'];
            $infos[$opid] = $opInfo;
        }else if (!isset($infos[$opid])) {
            ($infos[$opid] = static::findOne(['id'=>$opid]) ?: []) &&
            $infos[$opid]['settings'] = Lev::getSettings($infos[$opid]['settings']);
        }
        return $infos[$opid];
    }

    public static function saveStaticInfo($opInfo)
    {
        static::saveFormCall([], $opInfo, $opInfo);
        static::staticInfo(0, $opInfo);
    }

    public static function adminDeleteIds($optab = '', array $ids = [])
    {
        if ($rmsg = Lev::actionOnce('userModelHelper::adminDeleteIds')) {
            return $rmsg;
        }

        $rs = parent::adminDeleteIds($optab, $ids); // TODO: Change the autogenerated stub
//        if (!isset($rs['error'])) {
//            $rs['joinMsg'] = {关联表类名}::adminDeleteIds($optab, $ids);
//        }
        return $rs;
    }

    public static function deleteAllWhere($where = [], $reload = 1)
    {
        if ($rmsg = Lev::actionOnce('userModelHelper::deleteAllWhere')) {
            return $rmsg;
        }

        $rs = parent::deleteAllWhere($where, $reload); // TODO: Change the autogenerated stub
//        if (!isset($rs['error'])) {
//            $rs['joinMsg'] = {关联表类名}::deleteAllWhere($where, $reload);
//        }
        return $rs;
    }

    public static $userinfos;
    public static function registerMudUser($uid, $where = [], array $insert = [])
    {
        return parent::registerMudUser($uid, $where, $insert); // TODO: Change the autogenerated stub
    }

    /**
     * 数据统计，
     */
    public static function statisticsv($modalObject = null, $where = ['tstatus' => 0], $update = ['tstatus' => 1], $limit = 2000, $astatusField = 'astatus', $totalsField = 'score', $totalswinField = 'awardscore', $totalnumField = '', $totalwinnumField = '', $field = '*')
    {
        //$modalObject === null &&
        //$modalObject = 'modules\levcc\table\pre_admin_user\userModelHelper';
        //$field === '*' &&
        //$field = 'id,pagename,ip,uid,iden,iptotal,pagetotal,tstatus,status,addtime';//统计字段
        //return levccRanksModelHelper::statisticsv($modalObject, $where, $update, $limit, $astatusField, $totalsField, $totalswinField, $totalnumField, $totalwinnumField, $field); // TODO: Change the autogenerated stub
        //适合统计用户数据
        Lev::showMessages('未初始化：代码文件位置 => '.__DIR__ . '/userModelHelper.php');
    }
}


class userModelHelper extends BaseUserModelMiddle {

    public static function allColumns()
    {
        return parent::allColumns(); // TODO: Change the autogenerated stub
    }

    public static function safeColumnsInpus($columns)
    {
        return parent::safeColumnsInpus($columns); // TODO: Change the autogenerated stub
    }

    /**
     * 数据类型转化，在自动生成的控制器中自行实现
     * @param $upData
     * @param bool $save 为真时，入库保存；为假时，出库显示
     * @return mixed
     */
    public static function formatUpdata($upData, $save = true)
    {
//        if ($save) {
//            isset($upData['comrate']) &&
//            $upData['comrate'] = round($upData['comrate'] * 1000);
//        }else {
//            isset($upData['comrate']) &&
//            $upData['comrate'] /= 1000;
//        }
        return parent::formatUpdata($upData, $save); // TODO: Change the autogenerated stub
    }

    public static function setFormSettings($settings, $result = [])
    {
        return parent::setFormSettings($settings, $result); // TODO: Change the autogenerated stub
    }

    public static function saveInputs($datas, $where = [], $inId = false, $tables = [], $inputs = [], $formSet = true, $tablesFormData = [])
    {
        return parent::saveInputs($datas, $where, $inId, $tables, $inputs, $formSet, $tablesFormData); // TODO: Change the autogenerated stub
    }

    public static function getNextSetup()
    {
        return parent::getNextSetup(); // TODO: Change the autogenerated stub
    }

    public static function inputsSetup()
    {
        return parent::inputsSetup(); // TODO: Change the autogenerated stub
    }

    public static function setupDesc()
    {
        return parent::setupDesc(); // TODO: Change the autogenerated stub
    }

}